WTL Controls
|
Back to the WTL Controls Home Page. |
An owner-drawn combo box featuring textual content with per-item colors and fonts. More...
#include <ODComboBox.h>
Public Member Functions | |
CODComboBox () noexcept | |
virtual | ~CODComboBox () |
void | SubclassComboBox (HWND wnd) |
Subclass a combobox control. More... | |
void | UnSubclassComboBox () |
Un-subclass main and component windows; free GDI resources. More... | |
void | SetAutoAdjustDropRectWidth (bool value) |
Change the AutoAdjustRectWidth state. More... | |
bool | GetAutoAdjustDropRectWidth () const |
Default: true . More... | |
void | SetMaxDropDownWidth (int value) |
Sets the upper limit to the width of the dropdown list, if it is being automatically adjusted. More... | |
int | GetMaxDropDownWidth () const |
Default: 400 pixels. More... | |
void | UpdateControlHeight () |
Update the combobox height to accomodate all content. More... | |
void | UpdateDropDownWidth () |
Force an update of the width of the drop down list. More... | |
bool | ODAddItem () |
Add new item to the end of the list box. More... | |
bool | ODAddItem (std::basic_string< TCHAR > text, COLORREF text_color, COLORREF back_color, HFONT font, int height, CHorzAlignment horz, CVertAlignment vert, bool wrap, bool use_ellipsis) |
Add a new item to the end of the list box, populated with specified data. More... | |
bool | ODInsertItem (int index) |
Insert an item. More... | |
bool | ODInsertItem (int index, std::basic_string< TCHAR > text, COLORREF text_color, COLORREF back_color, HFONT font, int height, CHorzAlignment horz, CVertAlignment vert, bool wrap, bool use_ellipsis) |
Insert a new item at the position indicated by index . More... | |
bool | ODRemoveItem (int index) |
Deletes an item from the drop-down list. More... | |
void | SetODItemText (int index, std::basic_string< TCHAR > text) |
Modify the text associated with a combobox item. More... | |
std::basic_string< TCHAR > | GetODItemText (int index) const |
Default: "" . More... | |
void | SetODItemBackColor (int index, COLORREF color) |
Modify the background color of the selected combobox item. More... | |
COLORREF | GetODItemBackColor (int index) const |
Default: COLOR_WINDOW . More... | |
void | SetODItemTextColor (int index, COLORREF color) |
Modify the text color of the selected combobox item. More... | |
COLORREF | GetODItemTextColor (int index) const |
Default: COLOR_WINDOWTEXT . More... | |
void | SetODItemFont (int index, HFONT font) |
Modify the font assigned to the selected combobox item. More... | |
HFONT | GetODItemFont (int index) const |
Default: The font assigned to the combo box when the CODComboItem object is instantiated. More... | |
void | SetODItemHeight (int index, int height) |
Modify the height of the selected combobox item. More... | |
int | GetODItemHeight (int index) const |
Default: The height of the control portion of the combobox at the time the CODComboItem is instantiated. More... | |
void | SetODItemHorzAlignment (int index, CHorzAlignment value) |
Modify the horizontal text alignment of the selected combobox item. More... | |
CHorzAlignment | GetODItemHorzAlignment (int index) const |
Default: haLeft . More... | |
void | SetODItemVertAlignment (int index, CVertAlignment value) |
Modify the vertical text aligment of the selected combobox item. More... | |
CVertAlignment | GetODItemVertAlignment (int index) const |
DefaultL: vaMiddle . More... | |
void | SetODItemWordWrap (int index, bool wrap) |
Modify the WordWrap state of the selected combobox item. More... | |
bool | GetODItemWordWrap (int index) const |
Default: false . More... | |
void | SetODItemUseEllipsis (int index, bool ellipsis) |
Modify the UseEllipsis state of the selected combobox item. More... | |
bool | GetODItemUseEllipsis (int index) const |
Default: true . More... | |
An owner-drawn combo box featuring textual content with per-item colors and fonts.
IMPORTANT: This class only works properly with 'drop-list' combo boxes (i.e; those created with the CBS_DROPDOWNLIST style flag), not 'simple' comboboxes (those created with the CBS_SIMPLE style flag) or ' drop down' comboboxes (those created with the CBS_DROPDOWN flag). In addition, CBS_HASSTRINGS must be FALSE
.
The owner-drawn style can be set to either fixed or variable (i.e., the combobox style can include either CBS_OWNERDRAW or CBS_OWNERDRAWVARIABLE). If variable owner-draw mode is selected, CBS_NOINTEGRALHEIGHT must also be included among the control's style flags.
CBS_SORT is supported; sorting will be based on the text content.
Finally, the dialog container must reflect all Owner Drawn messages (WM_DRAWITEM, WM_MEASUREITEM, WM_COMPAREITEM and WM_DELETEITEM) back to the control, either with the non-discriminating REFLECT_NOTIFICATIONS_EX, or with something more selective (e.g, REFLECT_NOTIFICATIONS_MSG_ID_FILETERED).
With the above caveats, usage is straight-forward.
Definition at line 56 of file ODComboBox.h.
|
noexcept |
Definition at line 90 of file ODComboBox.cpp.
|
virtual |
Definition at line 103 of file ODComboBox.cpp.
void BIS_WTL_CONTROLS::CODComboBox::SubclassComboBox | ( | HWND | hWnd | ) |
Subclass a combobox control.
This also grabs the window handles of the list box and control portions of the combobox. Note that the control portion can be either a static text control or a edit control, depending on whether or not the contents of the combobox can be edited.
hWnd | The window handle of the control to subclass. |
void |
Definition at line 121 of file ODComboBox.cpp.
void BIS_WTL_CONTROLS::CODComboBox::UnSubclassComboBox | ( | ) |
Un-subclass main and component windows; free GDI resources.
Definition at line 148 of file ODComboBox.cpp.
void BIS_WTL_CONTROLS::CODComboBox::SetAutoAdjustDropRectWidth | ( | bool | value | ) |
Change the AutoAdjustRectWidth state.
value | New bool state. |
void |
Definition at line 190 of file ODComboBox.cpp.
bool BIS_WTL_CONTROLS::CODComboBox::GetAutoAdjustDropRectWidth | ( | ) | const |
Default: true
.
If true
, the drop box width is adjusted to accommodate the longest string in the list box. The width will not be less than the control width, and will not be greater than the max limit set through SetMaxDropDownWidth. if false
, drop down width will be equal to the control width.
bool |
Definition at line 175 of file ODComboBox.cpp.
void BIS_WTL_CONTROLS::CODComboBox::SetMaxDropDownWidth | ( | int | value | ) |
Sets the upper limit to the width of the dropdown list, if it is being automatically adjusted.
value | New maximum, in pixels. |
void |
Definition at line 219 of file ODComboBox.cpp.
int BIS_WTL_CONTROLS::CODComboBox::GetMaxDropDownWidth | ( | ) | const |
Default: 400 pixels.
The maximum width allowed when AutoAdjustDropRectWidth is true
.
int |
Definition at line 205 of file ODComboBox.cpp.
void BIS_WTL_CONTROLS::CODComboBox::UpdateControlHeight | ( | ) |
Update the combobox height to accomodate all content.
The width of the combobox's footprint is left unchanged, but the height of the rectangle is recaulculated to allow for the current contents of the listbox. Useful afer adding or removing items from the list.
void |
Definition at line 784 of file ODComboBox.cpp.
void BIS_WTL_CONTROLS::CODComboBox::UpdateDropDownWidth | ( | ) |
Force an update of the width of the drop down list.
If AutoAdjustWidth is true, the drop-down width will be set equal to the length of the longest string in the list box, within limits: if the length of the longest string is less than the width of the control portion of the combobox, the width will be set to the width of the control portion, and if the width of the longest string is greater than the MaxDropDownWidth value, the width will be set to MaxDropDownWidth.
If AutoAdjustWidth is /c true, the width of the dropdown list will be set equal to the width of the control portion of the combobox.
void |
Definition at line 741 of file ODComboBox.cpp.
bool BIS_WTL_CONTROLS::CODComboBox::ODAddItem | ( | ) |
Add new item to the end of the list box.
The new item will be instantiated with default values; current control font will be assigned to new item, and item height will be set to control window (edit or static) height.
bool | True is item is successfully added. |
Definition at line 235 of file ODComboBox.cpp.
bool BIS_WTL_CONTROLS::CODComboBox::ODAddItem | ( | std::basic_string< TCHAR > | text, |
COLORREF | text_color, | ||
COLORREF | back_color, | ||
HFONT | font, | ||
int | height, | ||
CHorzAlignment | horz, | ||
CVertAlignment | vert, | ||
bool | wrap, | ||
bool | use_ellipsis | ||
) |
Add a new item to the end of the list box, populated with specified data.
text | |
text_color | |
back_color | |
font | |
height | |
horz | |
vert | |
wrap | |
use_ellipsis |
bool | True is item is successfully added. |
Definition at line 270 of file ODComboBox.cpp.
bool BIS_WTL_CONTROLS::CODComboBox::ODInsertItem | ( | int | index | ) |
Insert an item.
The new item will be instantiated with default values; current control font will be assigned to new item, and item height will be set to control window (edit or static) height.
index | The zero-based index of the position at which to insert the new item. If this parameter is -1, the item is added to the end of the list. |
bool | True is item is successfully inserted. |
Definition at line 311 of file ODComboBox.cpp.
bool BIS_WTL_CONTROLS::CODComboBox::ODInsertItem | ( | int | index, |
std::basic_string< TCHAR > | text, | ||
COLORREF | text_color, | ||
COLORREF | back_color, | ||
HFONT | font, | ||
int | height, | ||
CHorzAlignment | horz, | ||
CVertAlignment | vert, | ||
bool | wrap, | ||
bool | use_ellipsis | ||
) |
Insert a new item at the position indicated by index
.
Inserts a new object at the position indicated by the zero-based index
parameter. If this parameter is -1, the item is added to the end of the list.
index | |
text | |
text_color | |
back_color | |
font | |
height | |
horz | |
vert | |
wrap | |
use_ellipsis |
bool | True is item is successfully inserted. |
Definition at line 348 of file ODComboBox.cpp.
bool BIS_WTL_CONTROLS::CODComboBox::ODRemoveItem | ( | int | index | ) |
Deletes an item from the drop-down list.
If the CB_HASSTRINGS flag is false (as it should be), calling DeleteString results in a WM_DELETEITEM message being sent; this is processed and the CODComboItem at the location indicated be index
is deleted.
index |
bool | True is item is successfully removed. |
Definition at line 389 of file ODComboBox.cpp.
void BIS_WTL_CONTROLS::CODComboBox::SetODItemText | ( | int | index, |
std::basic_string< TCHAR > | text | ||
) |
Modify the text associated with a combobox item.
index | The zero-based index of the item to modify. |
text | New text. |
void |
Definition at line 426 of file ODComboBox.cpp.
std::basic_string< TCHAR > BIS_WTL_CONTROLS::CODComboBox::GetODItemText | ( | int | index | ) | const |
Default: ""
.
Returns the text associated with the indicated combobox item.
index | Zero-based item index. |
std::basic_string<TCHAR> | The selected item's current text. |
Definition at line 407 of file ODComboBox.cpp.
void BIS_WTL_CONTROLS::CODComboBox::SetODItemBackColor | ( | int | index, |
COLORREF | color | ||
) |
Modify the background color of the selected combobox item.
index | The zero-based index of the item to modify. |
color | The new background color. |
void |
Definition at line 464 of file ODComboBox.cpp.
COLORREF BIS_WTL_CONTROLS::CODComboBox::GetODItemBackColor | ( | int | index | ) | const |
Default: COLOR_WINDOW
.
Returns the background color of the selected combobox item.
index | Zero-based item index. |
COLORREF | The selected item's current background color. |
Definition at line 445 of file ODComboBox.cpp.
void BIS_WTL_CONTROLS::CODComboBox::SetODItemTextColor | ( | int | index, |
COLORREF | color | ||
) |
Modify the text color of the selected combobox item.
index | The zero-based index of the item to modify. |
color | The new text color. |
void |
Definition at line 501 of file ODComboBox.cpp.
COLORREF BIS_WTL_CONTROLS::CODComboBox::GetODItemTextColor | ( | int | index | ) | const |
Default: COLOR_WINDOWTEXT
.
Returns the text color of the selected combobox item.
index | Zero-based item index. |
COLORREF | The selected item's current text color. |
Definition at line 482 of file ODComboBox.cpp.
void BIS_WTL_CONTROLS::CODComboBox::SetODItemFont | ( | int | index, |
HFONT | font | ||
) |
Modify the font assigned to the selected combobox item.
index | The zero-based index of the item to modify. |
font | The handle to the new font. |
void |
Definition at line 537 of file ODComboBox.cpp.
HFONT BIS_WTL_CONTROLS::CODComboBox::GetODItemFont | ( | int | index | ) | const |
Default: The font assigned to the combo box when the CODComboItem object is instantiated.
Returns the handle of the selected item's font.
index | Zero-based item index. |
HFONT | The handle of the selected item's font. |
Definition at line 518 of file ODComboBox.cpp.
void BIS_WTL_CONTROLS::CODComboBox::SetODItemHeight | ( | int | index, |
int | height | ||
) |
Modify the height of the selected combobox item.
index | The zero-based index of the item to modify. |
height | The new height. |
void |
Definition at line 575 of file ODComboBox.cpp.
int BIS_WTL_CONTROLS::CODComboBox::GetODItemHeight | ( | int | index | ) | const |
Default: The height of the control portion of the combobox at the time the CODComboItem is instantiated.
Returns the current height of the selected combobox item.
index | Zero-based item index. |
int | The selected item's current height. |
Definition at line 556 of file ODComboBox.cpp.
void BIS_WTL_CONTROLS::CODComboBox::SetODItemHorzAlignment | ( | int | index, |
CHorzAlignment | value | ||
) |
Modify the horizontal text alignment of the selected combobox item.
index | The zero-based index of the item to modify. |
value | The new horizontal alignment. |
void |
Definition at line 611 of file ODComboBox.cpp.
CHorzAlignment BIS_WTL_CONTROLS::CODComboBox::GetODItemHorzAlignment | ( | int | index | ) | const |
Default: haLeft
.
Returns the current horizontal text alignment of a selected combobox item.
index | Zero-based item index. |
CHorzAlignment | The current horizontal alignment. |
Definition at line 592 of file ODComboBox.cpp.
void BIS_WTL_CONTROLS::CODComboBox::SetODItemVertAlignment | ( | int | index, |
CVertAlignment | value | ||
) |
Modify the vertical text aligment of the selected combobox item.
index | The zero-based index of the item to modify. |
value | The new vertical alignment. |
void |
Definition at line 647 of file ODComboBox.cpp.
CVertAlignment BIS_WTL_CONTROLS::CODComboBox::GetODItemVertAlignment | ( | int | index | ) | const |
DefaultL: vaMiddle
.
Returns the current vertical text alignment of the sleected combobox item.
index | Zero-based item index. |
CVertAlignment | The current vertical alignment. |
Definition at line 628 of file ODComboBox.cpp.
void BIS_WTL_CONTROLS::CODComboBox::SetODItemWordWrap | ( | int | index, |
bool | wrap | ||
) |
Modify the WordWrap state of the selected combobox item.
If the WordWrap state of a combobox item is /c true, the DT_WORDBREAK flag is applied when text is drawn. If WordWrap is /c false. the DT_SINGLELINE flag is applied. See the MSDN documentation for the DrawText API for more information.
index | The zero-based index of the item to modify. |
wrap | The new bool state. |
void |
Definition at line 685 of file ODComboBox.cpp.
bool BIS_WTL_CONTROLS::CODComboBox::GetODItemWordWrap | ( | int | index | ) | const |
Default: false
.
Returns the current WordWrap state of the selected combobox item.
index | Zero-based item index. |
bool | The current WordWrap state. |
Definition at line 664 of file ODComboBox.cpp.
void BIS_WTL_CONTROLS::CODComboBox::SetODItemUseEllipsis | ( | int | index, |
bool | ellipsis | ||
) |
Modify the UseEllipsis state of the selected combobox item.
if the UseEllipsis state of a combobox item is /c true, the DT_ENDELLIPSIS flag is applied when text is drawn. See the MSDN documentation for the DrawText API for more information.
index | The zero-based index of the item to modify. |
ellipsis | The new bool state. |
void |
Definition at line 722 of file ODComboBox.cpp.
bool BIS_WTL_CONTROLS::CODComboBox::GetODItemUseEllipsis | ( | int | index | ) | const |
Default: true
.
Returns the current UseEllipsis state of the selected combobox item.
index | Zero-based item index. |
bool | The current UseEllipsis state. |
Definition at line 702 of file ODComboBox.cpp.